package com.king.scheduler;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
import org.quartz.SchedulerException;

public class MyListener implements JobListener {

	@Override
	public String getName() {
		return "My Listener";
	}

	@Override
	public void jobToBeExecuted(JobExecutionContext context) {
		System.out.println("job to be executed");
	}

	@Override
	public void jobExecutionVetoed(JobExecutionContext context) {
		System.out.println("job execution vetoed");
	}

	@Override
	public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
		if(jobException != null){
			try {
				//停止Scheduler
				context.getScheduler().shutdown();
				System.out.println("Error occurs when executing jobs, shut down the scheduler ");
				// 给管理员发送邮件…
			} catch (SchedulerException e) {
				e.printStackTrace();
			}
		}
	}
}